<link rel="stylesheet" href="__PUBLIC__/admin/css/bootstrap.css">
<style type="text/css">
    .modals {
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        left: 0;
        z-index: 1050;
        display: none;
        outline: 0;
    }
</style>
            <div class="content"> 
                <div class="operation">
                    <div class="pull-left">
                        <a href="/Agent/Agent/hexcel?user_id={$user_id}" class="exports"><button data-toggle="modal" data-target=".bs-example-modal-lg"><span class="glyphicon glyphicon-plus"></span>导出</button></a>
                    </div>
                    <div class="pull-left">
                        <button class="line"><span class="glyphicon glyphicon-plus"></span></button>
                    </div>
                    <div class="pull-left">
                        <a href="/Agent/Agent/user?user_id={$user_id}&status=0"><button class="line">待优化</span></button></a>
                    </div>
                    <div class="pull-left">
                        <a href="/Agent/Agent/user?user_id={$user_id}&status=1"><button class="line">优化中</span></button></a>
                    </div>
                    <div class="pull-left">
                        <button class="stop">停止优化</span></button>
                    </div>
                    <div class="pull-left">
                        <a href="/Agent/Agent/user?user_id={$user_id}"><button class="stop">全部</span></button></a>
                    </div>
                    <div class="right-box">
                        <input type="search" placeholder="关键词搜索..." name="search" class="search" value="{$search}">
                        <span class="glyphicon glyphicon-search" id="sub"></span>
                    </div>
                     <div class="right-box">
                        <select name="seo" class="seo" onchange="show_sub(this.options[this.options.selectedIndex].value)">
                            <option value="0">全部</option>
                            <option value="1" <if condition="$seo eq 1 "> selected = "selected" </if>>百度PC</option>
                            <option value="2" <if condition="$seo eq 2 "> selected = "selected" </if>>百度移动</option>
                            <option value="3" <if condition="$seo eq 3 "> selected = "selected" </if>>360PC</option>
                            <option value="4" <if condition="$seo eq 4 "> selected = "selected" </if>>360移动</option>
                            <option value="5" <if condition="$seo eq 5 "> selected = "selected" </if>>搜狗PC</option>
                            <option value="6" <if condition="$seo eq 6 "> selected = "selected" </if>>搜狗移动</option>
                        </select>
                        
                    </div>
                </div>
                <table class="table agent">
                    <tbody>
                    <tr>
                        <th><input type="checkbox"/ id="all" name="all"></th>
                        <volist name="header" id="vo">
                            <th>{$vo}
                                <span>
                                    <a class="glyphicon glyphicon-triangle-top"></a>
                                    <a class="glyphicon glyphicon-triangle-bottom"></a>
                                </span>
                            </th>
                        </volist> 
                    </tr>
                        <volist name="list" id="vo">
                        <tr>
                            <td><input type="checkbox"/ name="box" class="{$vo['id']}"></td>
                            <volist name="vo" id="v">
                                <td>{$v}</td>
                            </volist>
                        </tr>
                        </volist>       
                </tbody>
                </table>
                <div class="page">
                    <span>共 {$count} 条</span>
                    <div class="paging">
                        {$page}
                    </div>
                    前往<input type="text" value="{$p}" name='page' onchange="mychange()">页
                </div>    
            </div>
        
    <div class="modals fade bs-example-modal-lgg">
            <div class="modal-dialog modal-lg">
              <div class="modal-content">
                    <table class="table" id="tables">
                      
                    </table>
                  <div class="page">
<!--                       <span>共 800 条</span>
                      每页
                      <select name="" id="">
                          <option value="10">10</option>
                          <option value="20">20</option>
                          <option value="30">30</option>
                          <option value="40">40</option>
                      </select>条
                      <div class="paging">
                          <a href="" title="首页" class="glyphicon glyphicon-chevron-left"></a>
                          <a href="" class="active">1</a>
                          <a href="">2</a>
                          <a href="">3</a>
                          <a href="">4</a>
                          <a href="">5</a>
                          <span>...</span>
                          <a href="">23</a>
                          <a href="" title="上一页" class="glyphicon glyphicon-chevron-right"></a>
                      </div>
                      前往<input type="text" value="10">页 -->
                  </div>    
              </div>
            </div>
          </div>

<script type="text/javascript">
    $(document).ready(function () {
        $('tr').find('th').eq(5).css({'display':'none'});
        $('tr').each(function (i){
          $(this).find('td').eq(5).css({'display':'none'});
        });

        var seo = '{$seo}';
        var exports = $('.exports').attr('href');
        $('.exports').attr('href',exports+'&seo='+seo);
    });

    $("#sub").click(function(){
        var user_id = '{$user_id}';   
        var search = $('.search').val();
        var seo = $('.seo').val();
        window.location.href = "/Agent/Agent/user.html?search="+search+'&seo='+seo+'&user_id='+user_id;
    });

    function show_sub(v){
        var user_id = '{$user_id}';     
        var search = $('.search').val();
        window.location.href = "/Agent/Agent/user.html?search="+search+'&seo='+v+'&user_id='+user_id;
    }

    $(".line").click(function(){
        var display = $('tr').find('th').eq(5).css('display');
        if(display == 'none'){
            $('tr').find('th').eq(5).css({'display':'block'});
            $('tr').each(function (i){
              $(this).find('td').eq(5).css({'display':'block'});
            });
            var exports = $('.exports').attr('href');
            $('.exports').attr('href',exports+'&amount=1');
        }else{
            $('tr').find('th').eq(5).css({'display':'none'});
            $('tr').each(function (i){
              $(this).find('td').eq(5).css({'display':'none'});
            });
            var exports = $('.exports').attr('href');
            $('.exports').attr('href',exports+'&amount=0');
        }
        
    });

    function mychange(){
      var user_id = '{$user_id}';  
      var page =  $('input[name="page"]').val();
      window.location.href = "/index.php/Agent/Agent/user/p/"+page+'/user_id/'+user_id;
    }

    document.onclick = function(e) {
        var modals = 　$('.modals').css('display');
        
        if(modals == 'block'){
            $('.modals').css('display','none');
            $(".modals").removeClass("show");
            $("body").removeClass("modal-open");
            $("body").css("padding-right",'0');
            $(".modal-backdrop").remove();
        }　　　　　
    }


    $(".add").click(function(){
        var user_id = $(this).attr('user_id');
        var seo = $(this).attr('seo');
        var keyword = $(this).attr('keyword');
        $.ajax({
            url:'/Agent/Agent/details',    //请求的url地址
            dataType: "JSON",   //返回格式为json
            async: true,//请求是否异步，默认为异步，这也是ajax重要特性
            type: "post",   //请求方式
            data:{
                user_id:user_id,
                seo:seo,
                keyword:keyword,
            },
            success: function (data) {
                if(data.state==1){
                    var html = '<tr><th>序号 <span><a class="glyphicon glyphicon-triangle-top"></a><a class="glyphicon glyphicon-triangle-bottom"></a></span></th><th>客户</th><th>关键词</th><th>交易时间</th><th>交易类别</th><th>资金变动</th><th>备注</th></tr>';
                    $.each(data.data, function (i, item) {
                        html += '<tr>';
                        $.each(item, function (q, items) {
                            html += "<td>"+items+"</td>";
                        });
                        html += '</tr>';
                    });
                    $('#tables').html();
                    $('#tables').html(html);

                }else{
                var html = '<tr><th>序号 <span><a class="glyphicon glyphicon-triangle-top"></a><a class="glyphicon glyphicon-triangle-bottom"></a></span></th><th>客户</th><th>关键词</th><th>交易时间</th><th>交易类别</th><th>资金变动</th><th>备注</th></tr>';
                $('#tables').html();
                $('#tables').html(html);
                    console.log(data.data)
                    return false;
                }
            }
        })

        $("body").addClass("modal-open");
        $(".modals").addClass("show");
        $('.modals').css('display','block');
        $('input[name="act"]').val('edit');
        $("body").append("<div class='modal-backdrop fade show'></div>");

    });

   
    $(".modal-content").click(function(event){
        event.stopPropagation();
    });

    $(".add").click(function(event){
        event.stopPropagation();
    });

    $(".stop").click(function(){
        var user_id = '{$user_id}';
        var chk_value = [];
        var all =  $("#all")[0].checked
        var checked = $('input[name=box]')
        for(var i = 0; i <checked.length; i ++){
            if(checked[i].checked){
                chk_value.push(checked[i].classList[0]);
            }
        }
        console.log(chk_value)
        var t = chk_value.length;
         var wid = JSON.stringify(chk_value);
         wid = $.parseJSON(wid);
        if(all &&  t > 1 || all){
            var wid = JSON.stringify(chk_value);
            wid = $.parseJSON(wid);
            $.ajax({
                url:'/Agent/Agent/stop',    //请求的url地址
                dataType: "JSON",   //返回格式为json
                async: true,//请求是否异步，默认为异步，这也是ajax重要特性
                type: "post",   //请求方式
                data:{
                    wid:wid,
                },
                success: function (data) {
                    if(data.state==1){
                        var url = '/Agent/Agent/user?status=2&user_id='+user_id;
                        window.location.href = url;
                    }else{
                        console.log(data.data)
                        return false;
                    }
                }
            })
        }else if(t > 1){
            var wid = JSON.stringify(chk_value);
            wid = $.parseJSON(wid);
            console.log(wid);
            $.ajax({
                url:'/Agent/Agent/stop',    //请求的url地址
                dataType: "JSON",   //返回格式为json
                async: true,//请求是否异步，默认为异步，这也是ajax重要特性
                type: "post",   //请求方式
                data:{
                    wid:wid,
                },
                success: function (data) {
                    if(data.state==1){
                        var url = '/Agent/Agent/user?status=2&user_id='+user_id;
                        window.location.href = url;
                    }else{
                        console.log(data.data)
                        return false;
                    }
                }
            })
        }else{
            var url = '/Agent/Agent/user?status=2&user_id='+user_id;
            window.location.href = url;
            console.log(url);
        }

       
    });


    $("#all").click(function(){
        // this 全选的复选框
        var userids=this.checked;
        //获取name=box的复选框 遍历输出复选框
        $("input[name=box]").each(function(){
            this.checked=userids;
        });
    });
</script>    
